package com.roamer.audition.server.converter;

import com.roamer.audition.common.request.*;
import com.roamer.audition.common.response.AuditionRecordDetailVO;
import com.roamer.audition.common.response.AuditionRecordVO;
import com.roamer.audition.server.entity.AuditionRecord;
import com.roamer.audition.server.query.AuditionRecordPageQuerySpecification;
import com.roamer.audition.server.query.AuditionRecordQuerySpecification;
import com.roamer.audition.server.query.AuditionRecordSimpleQuerySpecification;
import org.mapstruct.*;

/**
 * 面试计划 数据转换接口
 *
 * @author roamer
 * @version V1.0
 * @date 2019/1/24 17:42
 */
@Mapper(nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
        nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, componentModel = "spring")
public interface AuditionRecordConverter {

    /**
     * DTO转换为Entity
     *
     * @param auditionRecordDTO DTO对象
     *
     * @return {@code AuditionRecord}
     */
    @Mapping(target = "score",
            expression = "java(com.roamer.audition.common.enums.ScoreEnum.getEnumByValue(auditionRecordDTO.getScore()))")
    @Mapping(target = "status",
            expression = "java(com.roamer.audition.common.enums.StatusEnum.getEnumByValue(auditionRecordDTO.getStatus()))")
    @Mapping(target = "result",
            expression = "java(com.roamer.audition.common.enums.ResultEnum.getEnumByValue(auditionRecordDTO.getResult()))")
    @Mapping(target = "company", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    AuditionRecord dtoToEntity(AuditionRecordDTO auditionRecordDTO);

    /**
     * SimpleDTO转换为Entity
     *
     * @param auditionRecordSimpleDTO SimpleDTO对象
     *
     * @return {@code AuditionRecord}
     */
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "endTime", ignore = true)
    @Mapping(target = "company", ignore = true)
    @Mapping(target = "status", ignore = true)
    @Mapping(target = "score", ignore = true)
    @Mapping(target = "result", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "deleted", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    AuditionRecord dtoToEntity(AuditionRecordSimpleDTO auditionRecordSimpleDTO);


    /**
     * 转换为VO
     *
     * @param auditionRecord Entity对象
     *
     * @return {@code AuditionRecordVO}
     */
    @Mapping(target = "score", source = "score.value")
    @Mapping(target = "status", source = "status.value")
    @Mapping(target = "result", source = "result.value")
    AuditionRecordVO entityToVO(AuditionRecord auditionRecord);


    /**
     * 转换为DetailVO
     *
     * @param auditionRecord Entity对象
     *
     * @return {@code AuditionRecordDetailVO}
     */
    @Mapping(target = "companyId", source = "company.id")
    @Mapping(target = "companyName", source = "company.companyName")
    @Mapping(target = "status", source = "status.value")
    AuditionRecordDetailVO entityToDetailVO(AuditionRecord auditionRecord);


    /**
     * Copy属性
     *
     * @param auditionRecordDTO 源DTO
     * @param auditionRecord    目标Entity
     */
    @Mapping(target = "score",
            expression = "java(com.roamer.audition.common.enums.ScoreEnum.getEnumByValue(auditionRecordDTO.getScore()))")
    @Mapping(target = "status",
            expression = "java(com.roamer.audition.common.enums.StatusEnum.getEnumByValue(auditionRecordDTO.getStatus()))")
    @Mapping(target = "result",
            expression = "java(com.roamer.audition.common.enums.ResultEnum.getEnumByValue(auditionRecordDTO.getResult()))")
    @Mapping(target = "company", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    void copyNotNullPropertiesFromDTO(AuditionRecordDTO auditionRecordDTO,
                                      @MappingTarget AuditionRecord auditionRecord);


    /**
     * 查询条件转换
     *
     * @param auditionRecordQuery 查询条件
     *
     * @return {@code AuditionRecordQuerySpecification}
     */
    AuditionRecordQuerySpecification queryToSpecification(AuditionRecordQuery auditionRecordQuery);


    /**
     * 分页查询条件转换
     *
     * @param auditionRecordPageQuery 查询条件
     *
     * @return {@code AuditionRecordPageQuerySpecification}
     */
    AuditionRecordPageQuerySpecification pageQueryToSpecification(AuditionRecordPageQuery auditionRecordPageQuery);

    /**
     * 简单查询条件转换
     *
     * @param auditionRecordSimpleQuery 查询条件
     *
     * @return {@code AuditionRecordSimpleQuerySpecification}
     */
    AuditionRecordSimpleQuerySpecification simpleQueryToSpecification(
            AuditionRecordSimpleQuery auditionRecordSimpleQuery);

}
